/****************************************************************************************
 * @file    KEY_LED.h
 *
 * @author  Shanon
 *
 * @version V1.0.0
 *
 * @date    02-08-2016
 *
 * @brief   KEY and LED header file.
 ***************************************************************************************/
#ifndef _KEY_LED_H
#define _KEY_LED_H

#include "stm32f4xx.h"

/****************************************************************************************
 * KEY status macro defines
 ***************************************************************************************/
#define WAKEUP    0x00
#define USER      0x01
#define JOY_A     0x02
#define JOY_B     0x03
#define JOY_C     0x04
#define JOY_D     0x05
#define JOY_CTR   0x06


/****************************************************************************************
 * LED GPIOs micro defines
 ***************************************************************************************/
#define LED1_Port						GPIOH                        /* Port */
#define LED1_Pin						GPIO_Pin_2                   /* Pin */
#define LED1_RCC_AHBPeriph				RCC_AHB1Periph_GPIOH         /* Clock */

#define LED2_Port						GPIOH
#define LED2_Pin						GPIO_Pin_3
#define LED2_RCC_AHBPeriph				RCC_AHB1Periph_GPIOH

#define LED3_Port						GPIOI
#define LED3_Pin						GPIO_Pin_8
#define LED3_RCC_AHBPeriph				RCC_AHB1Periph_GPIOI

#define LED4_Port						GPIOI
#define LED4_Pin						GPIO_Pin_10
#define LED4_RCC_AHBPeriph				RCC_AHB1Periph_GPIOI

/****************************************************************************************
 * KEY GPIOs micro defines
 ***************************************************************************************/
#define USER_KEY_Port					GPIOF
#define USER_KEY_Pin					GPIO_Pin_10
#define USER_KEY_RCC_AHBPeriph			RCC_AHB1Periph_GPIOF

#define WAKEUP_KEY_Port					GPIOA
#define WAKEUP_KEY_Pin					GPIO_Pin_0
#define WAKEUP_KEY_RCC_AHBPeriph		RCC_AHB1Periph_GPIOA

#define JOY_A_KEY_Port					GPIOE
#define JOY_A_KEY_Pin					GPIO_Pin_2
#define JOY_A_KEY_RCC_AHBPeriph			RCC_AHB1Periph_GPIOE

#define JOY_B_KEY_Port					GPIOE
#define JOY_B_KEY_Pin					GPIO_Pin_3
#define JOY_B_KEY_RCC_AHBPeriph			RCC_AHB1Periph_GPIOE

#define JOY_C_KEY_Port					GPIOE
#define JOY_C_KEY_Pin					GPIO_Pin_4
#define JOY_C_KEY_RCC_AHBPeriph			RCC_AHB1Periph_GPIOE

#define JOY_D_KEY_Port					GPIOE
#define JOY_D_KEY_Pin					GPIO_Pin_5
#define JOY_D_KEY_RCC_AHBPeriph			RCC_AHB1Periph_GPIOE

#define JOY_CTR_KEY_Port				GPIOE
#define JOY_CTR_KEY_Pin					GPIO_Pin_6
#define JOY_CTR_KEY_RCC_AHBPeriph		RCC_AHB1Periph_GPIOE 

/****************************************************************************************
 * PS GPIOs micro defines
 ***************************************************************************************/
#define PS_ATT_Port                     GPIOI
#define PS_ATT_Pin                      GPIO_Pin_4                //Control signal
#define PS_ATT_RCC_AHBPeriph            RCC_AHB1Periph_GPIOI 

#define PS_CLK_Port                     GPIOI
#define PS_CLK_Pin                      GPIO_Pin_5                //Clock signal
#define PS_CLK_RCC_AHBPeriph            RCC_AHB1Periph_GPIOI 

#define PS_CMD_Port                     GPIOI
#define PS_CMD_Pin                      GPIO_Pin_6                //Command signal
#define PS_CMD_RCC_AHBPeriph            RCC_AHB1Periph_GPIOI 

#define PS_DAT_Port                     GPIOI
#define PS_DAT_Pin                      GPIO_Pin_7                //Data signal
#define PS_DAT_RCC_AHBPeriph            RCC_AHB1Periph_GPIOI

/****************************************************************************************
 * LED and KEY Function Prototypes
 ***************************************************************************************/
void KEY_Init( void );

void LED_Init( void );

uint8_t Read_KEY_State( void );
uint8_t GetKeyPosition(void);

void Led_Toggle( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin );

#endif /*_KEY_LED_H*/
